export function showToastBack(title) {
    uni.showToast({
        icon: 'none',
        title
    })
    uni.navigateBack();
}
export function getAgeByIdCard(idCard) {
    if (idCard.length!== 18) {
        throw new Error('请输入有效的18位身份证号');
    }
    const birthDateStr = idCard.substring(6, 10);
    const birthDate = new Date(birthDateStr);
    const currentDate = new Date();
    let age = currentDate.getFullYear() - birthDate.getFullYear();
    const monthDiff = currentDate.getMonth() - birthDate.getMonth();
    if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;
}

// 身份证号验证
export function regexIdCard(idCard) {
    const regex = /^[1 - 9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
    return regex.test(idCard);
}

// 手机号正则表达式
export function validatePhone(phone) {
    const phoneRegExp = /^1[3-9]\d{9}$/;
    return phoneRegExp.test(phone);
}
